package com.ecommerce.chat.config;

import okhttp3.OkHttpClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import lombok.Data;

import java.util.concurrent.TimeUnit;

/**
 * AI客服配置类
 */
@Configuration
@ConfigurationProperties(prefix = "chat.deepseek")
@Data
public class ChatConfig {
    
    /**
     * DeepSeek API地址
     */
    private String apiUrl = "https://api.deepseek.com/chat/completions";
    
    /**
     * API密钥
     */
    private String apiKey;
    
    /**
     * 连接超时时间（秒）
     */
    private Integer connectTimeout = 30;
    
    /**
     * 读取超时时间（秒）
     */
    private Integer readTimeout = 60;
    
    /**
     * 写入超时时间（秒）
     */
    private Integer writeTimeout = 60;
    
    /**
     * 默认系统提示词
     */
    private String systemPrompt = "你是一个专业的电商客服助手，请用友好、专业的语气回答用户的问题。如果遇到不确定的问题，请引导用户联系人工客服。";
    
    /**
     * 最大重试次数
     */
    private Integer maxRetries = 3;
    
    /**
     * 配置OkHttp客户端
     */
    @Bean
    public OkHttpClient okHttpClient() {
        return new OkHttpClient.Builder()
                .connectTimeout(connectTimeout, TimeUnit.SECONDS)
                .readTimeout(readTimeout, TimeUnit.SECONDS)
                .writeTimeout(writeTimeout, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                .build();
    }
}